import sort.comparison.MergeBU;

import java.util.*;

public class Main {

    private static Comparable[] array;

    public static Comparable[] repeatArray() {
        return instance(20, 10, true);
    }

    public static Comparable[] unRepeatArray() {
        return instance(10, 0, false);
    }

    public static Comparable[] instance(int length, int range, boolean repeat) {
        if (repeat)
            setArray(length, range);
        else
            setArray(length);
        return array;
    }

    private static void setArray(int length, int range) {
        array = new Comparable[length];
        Random random = new Random();
        for (int i = 0; i < length; i++)
            array[i] = random.nextInt(range);
    }

    private static void setArray(int length) {
        array = new Comparable[length];
        for (int i = 0; i < length; i++)
            array[i] = i + 1;
        shuffle(array);
    }

    private static void shuffle(Comparable[] array) {
        Random random = new Random();
        for (int i = array.length; i > 1; i--)
            swap(array, i - 1, random.nextInt(i));
    }

    private static void swap(Comparable[] arr, int i, int j) {
        Comparable tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    public static void main(String[] args) {
        Comparable[] ints = unRepeatArray();
//        Shell.sort(ints);
//        Merge.sort(ints);
        MergeBU.sort(ints);
        System.out.println(Arrays.toString(ints));
    }

}
